﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UCWebpart.Admin
{
    public partial class blackList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string blackName = TextBox1.Text;
            if(string.IsNullOrWhiteSpace(blackName)){
                return;
            }
            if (CheckUserName(blackName) < 1)
            {
                Label1.Text = "<script>alert('您输入的人员不存在！'); </script>";
                return;
            }
            insertIntoBlackList(blackName);
            Label1.Text = "<script>alert('已将" + blackName + "加入黑名单'); </script>";
        }

        public void insertIntoBlackList(string blackName)
        {
            string conn = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;//"Data Source=mesdbsrv.gwkf.cn;Initial Catalog=VenueBooking;User ID=vbuser;Password=vb_2013";
            string strSQL = string.Format("insert into [VenueBooking].[dbo].[blackList] (blackName,available) values ('{0}',1)", blackName);
            Worker.doSql(strSQL, conn);
        }

        public int CheckUserName(string userName)
        {
            string cString = WebConfigurationManager.ConnectionStrings["WorkFlowConnectionString"].ConnectionString;
            string strSQL = string.Format(@"select 1 from [WorkFlow].[dbo].[RUC_Users] where SamAccountName='{0}' and IfDelete=0", userName);
            DataTable dt = Worker.GetDataSet(strSQL, cString).Tables[0];
            return dt.Rows.Count;
        }
    }
}